-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new "MapAction" overloads #30556
Conversation
src/Http/Routing/src/Builder/MapActionEndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
Hello @halter73! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
/// <param name="pattern">The route pattern.</param> | ||
/// <param name="action">The delegate executed when the endpoint is matched.</param> | ||
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns> | ||
public static MapActionEndpointConventionBuilder MapGet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there already Map* extension methods on route builder? Do these not colide because of Delegate
parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are overloads, but they should only be used for delegates that aren't RequestDelegate
s. This was also mentioned in dotnet/csharplang#4451 (comment).
/// <param name="action">The delegate executed when the endpoint is matched.</param> | ||
/// <param name="httpMethods">HTTP methods that the endpoint will match.</param> | ||
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns> | ||
public static MapActionEndpointConventionBuilder MapMethods( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? As a user, there are alternate ways to re-use the delegate if we need to. I'm also similarly against allowing more than one HTTP attributes per MapAction delegate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the flexibility of delegates means that we shouldn't need to make routing metadata overly complicated. That's why I removed IRotePatternMetadata
and IRouteOrderMetadata
in #30563. I also stopped implementing IHttpMethodMetadata
in attributes which caused multiple instances to show up on endpoints that didn't have multiple instances before. #29878 (comment)
All that said, this is an overload that already exists for RequestDelegate
and any argument about reusing the Delegate
, you could make for reusing the RequestDelegate
. I'm just keeping it consistent by adding a Delegate
overload for every RequestDelegate
overload.
Fixes #30448.
By adding overloads to existing built-in IEndpointRouteBuilder extension methods, we remove the need for the routing attributes (
[HttpGet("/"]
,[HttpPost(...
, etc.) in front of most "MapAction" methods. This will be especially handy when the methods become lambdas in non-trivial cases.This leaves
MapAction
for now. I'll have a PR that removes that andIRoutePatternMetadata
soon.